import Cookies from "js-cookie"

export default {
    namespaced:true,
    state:{
        ishidden:false,
        menudata:[],
    },
    mutations:{
        changeishidden(state){
            state.ishidden = !state.ishidden
        },
        breadlist(){},
        setmenu(state,val){
            state.menudata = val
            Cookies.set('menu',JSON.stringify(val))
        },
        enrollroute(state,router){
            if(!Cookies.get('menu')) return
            const menu = JSON.parse(Cookies.get('menu'))
            state.menudata = menu
            const routedata = JSON.parse(Cookies.get('route'))
            const realroute = []
            routedata.forEach(item => {
                if(item.children){
                    item.children.map(item => {
                        item.component = () => import(`../pages/${item.url}`)
                        return item
                    })
                    realroute.push(...item.children)
                }else{
                    item.component = () => import(`../pages/${item.url}`)
                    realroute.push(item)
                }
            });
            realroute.forEach(item => {
                router.addRoute('home',item)
            })
            
        }
    }
}